package edu.towson.cis.cosc442.project3.vendingmachine;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Rule;
import org.junit.rules.ExpectedException;

public class VendingMachineItemTest {
	VendingMachineItem item;
	
	@Rule public ExpectedException thrown = ExpectedException.none();
	
	//Set up an initial item called "Snack" with a price of $3.50
	@Before
	public void setUp(){
		item = new VendingMachineItem("Snack", 3.50);	
	}	
	
	//Tests if the constructor gives the correct name to the item
	@Test
	public void testConstructorName() {
		item = new VendingMachineItem("Popcorn", 2.50);
		assertEquals("Popcorn", item.getName());
	}
	
	//Tests if the constructor gives the correct price to the item
	@Test
	public void testConstructorPrice() {
		item = new VendingMachineItem("Popcorn", 2.50);
		assertEquals(2.50, item.getPrice(), .05);
				
	}
	
	
	//Tests if exception is thrown when price is negative
	@Test 
	public void testConstructorException(){		
		thrown.expect(VendingMachineException.class);
		item = new VendingMachineItem("MoreThanFree", -5);
	}
	
	//Tests if the correct name is returned
	@Test
	public void testGetName(){
		assertEquals("Snack", item.getName());
	}

	//Tests if the correct price is returned
	@Test
	public void testGetPrice(){
		assertEquals(3.50, item.getPrice(), .05);
	}
	
	//Set the expected exception thrown to none
	@After
	public void tearDown(){
		thrown = ExpectedException.none();
	}
	
	
}
